import request from '@/router/axios';

/**
 * 获取用户列表
 * @param {String,Number} current 页码 
 * @param {String,Number} size    每页数据量
 * @param {Object} params 页码 
 */
export const getList = (current, size, params, deptId) => {
  return request({
    url:'/system/user/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
      deptId
    }
  })
}

export const remove = (ids) => {
  return request({
    url: '/system/user/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

export const add = (row) => {
  return request({
    url: '/system/user/submit',
    method: 'post',
    data: row
  })
}

export const update = (row) => {
  return request({
    url: '/system/user/submit',
    method: 'post',
    data: row
  })
}

// 用户详情
export const getUser = (id) => {
  return request({
    url: '/system/user/detail',
    method: 'get',
    params: {
      id,
    }
  })
}

/**
 * 重置密码
 * @param {String} userIds 用户id（逗号分隔字符串） 
 */
export const resetPassword = (userIds) => {
  return request({
    url: '/system/user/reset-password',
    method: 'post',
    params: {
      userIds,
    }
  })
}

// 修改密码
export const updatePassword = (oldPassword, newPassword, newPassword1) => {
  return request({
    url: '/system/user/update-password',
    method: 'post',
    params: {
      oldPassword,
      newPassword,
      newPassword1,
    }
  })
}

// 获取用户信息
export const getUserInfo = () => request({
  url: '/system/user/info',
  method: 'get'
});

// 用户专用编辑用户信息接口（不需要传用户id）
export const updateInfo = (row) => {
  return request({
    url: '/system/user/update-info',
    method: 'post',
    data: row
  })
}

/**
 * 为指定用户绑定角色
 * @param {String} userId 用户id
 * @param {String} roleIds 角色id（多个用逗号分隔）
 */
export const grant = (userId, roleIds) => {
  return request({
    url: '/system/user/grant',
    method: 'post',
    params: {
      userId,
      roleIds,
    }
  })
}

/**
 * 账号解封
 * @param {String} userIds 用户id（逗号分隔字符串）
 */
export const unlock = (userIds) => {
  return request({
    url: '/system/user/unlock',
    method: 'post',
    params: {
      userIds,
    }
  })
}


/**
 * 登陆
 * @param {String} username 账号
 * @param {String} password 密码
 * @param {String} code     验证码
 */
export const loginByUsername = (username, password, code) => request({
  url: '/system/user/login',
  method: 'post',
  data: {
    username,
    password,
    code,
  }
})

/**
 * 通过refresh_token刷新token
 */
export const refreshToken = (refresh_token) => request({
  url: '/system/user/token/refresh',
  method: 'post',
  data: {
    refresh: refresh_token,
  },
  source: true
});

// 退出登陆
export const logout = (refresh_token) => request({
  url: '/system/user/logout',
  method: 'get',
  params: {
    refresh_token
  }
})

// base64图片验证码
export const getCaptcha = () => request({
  url: '/system/user/captcha',
  method: 'get'
})

// 获取按钮权限
export const getButtons = () => request({
  url: '/system/menu/buttons',
  method: 'get'
});

// 发送错误日志（未实现）
export const sendLogs = (list) => request({
  url: '/user/logout',
  method: 'post',
  data: list
})